/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.EditPanes.Filter;

import B3D_Elements.B3D_Filters.B3D_FrostedGlass;
import GUI.Components.BTextField;
import GUI.EditPanes.EditTaskPane;
import General.CurrentData;
import com.shaderblow.filter.frostedglass.FrostedGlassFilter;
import other.ObjectToElementConverter;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.Callable;
import javax.swing.JLabel;
import se.datadosen.component.RiverLayout;

/**
 *
 * @author David
 */
public class FrostedGlassTaskPane extends EditTaskPane
{

    private BTextField randomFactorField, randomScaleField;

    public FrostedGlassTaskPane(final FrostedGlassFilter filter)
    {
        randomFactorField = new BTextField("Float", Float.toString(filter.getRandomFactor()));
        randomScaleField = new BTextField("Float", Float.toString(filter.getRandomScale()));
        add(taskPane, BorderLayout.CENTER);
        applyButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Void>()
                {
                    public Void call() throws Exception
                    {
                        CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().removeFilter(
                                filter);
                        CurrentData.getEditorWindow().getB3DApplication().getElementList().removeByObject(filter);
                        CurrentData.getEditorWindow().getB3DApplication().setSelectedElement(null, null);
                        filter.setRandomFactor(Float.parseFloat(randomFactorField.getText()));
                        filter.setRandomScale(Float.parseFloat(randomScaleField.getText()));
                        CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(
                                filter);
                        B3D_FrostedGlass b3D_FrostedGlass = ObjectToElementConverter.convertFrostedGlass(filter);
                        CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(filter, b3D_FrostedGlass);
                        CurrentData.getEditorWindow().getB3DApplication().setSelectedElement(b3D_FrostedGlass.getID());
                        CurrentData.getEditorWindow().getTree().sync();
                        CurrentData.getEditorWindow().getEditPane().arrange(false);
                        return null;
                    }
                });
            }
        });
        taskPane.setLayout(new RiverLayout());
        taskPane.setTitle("Frosted Glass Filter");
        taskPane.add("left", new JLabel("Random Factor:"));
        taskPane.add("tab hfill", randomFactorField);
        taskPane.add("br left", new JLabel("Random Scale:"));
        taskPane.add("tab hfill", randomScaleField);
        taskPane.add("br right", applyButton);
    }
}
